'use strict';

import { usertokenModel } from "../model/usertoken";
import { ServiceBase, Exceptions } from '../kalend';
import { ObjectId } from "bson";

class UsertokenService extends ServiceBase {
    constructor() {
        super(usertokenModel)
    }
    async getToken(token: any) {
        if (!token) {
            throw Exceptions.notoken();
        }
        let userdata = await this.querySingle({ tokencode: token });
        if (userdata && userdata.openid) {
            return userdata;
        } else {
            throw Exceptions.known('获取用户信息失败');
        }
    }
}

export const usertokenService = new UsertokenService();